package com.diy.sigmund.diycommon.spring.config;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 自定义logback日志打印字段
 *
 * @author ylm-sigmund
 * @since 2021/8/27 16:17
 */
public class CustomLogBackIpConfig extends ClassicConverter {

    private static final Logger log = LoggerFactory.getLogger(CustomLogBackIpConfig.class);

    @Override
    public String convert(ILoggingEvent event) {
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            log.error("获取日志Ip异常", e);
        }
        return ip;
    }

}
